import 'dart:math';

import 'package:flutter/material.dart';

// 通用 Sliver 悬停 delegate
class BLSliverPersistentDelegate extends SliverPersistentHeaderDelegate {

  final Widget child;
  final double maxHeight;
  final double minHeight;

  BLSliverPersistentDelegate({
    @required this.child,
    @required this.maxHeight,
    @required this.minHeight,
  });

  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    //尽可能大
    return SizedBox.expand(child: child,);
  }

  @override
  // 最大高度
  double get maxExtent => max(maxHeight, minHeight);

  @override
  // 最小高度
  double get minExtent => min(maxHeight, minHeight);

  // 是否需要重绘
  @override
  bool shouldRebuild(BLSliverPersistentDelegate oldDelegate) {
    return maxExtent != oldDelegate.maxExtent ||
        minExtent != oldDelegate.minExtent ||
        child != oldDelegate.child;
  }

}